package job;


import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Scanner;

public class Test {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        //  SubjectDao u = new SubjectDao();
        StudentDao u = new StudentDao();
        while (true) {
            System.out.println("1,添加学生  2，修改学生信息，3，删除学生（通过学号）  4，通过学号查询学生信息   5,通过姓名查询（模糊查询） 6，通过QQ,telephone，姓名查找学生（模糊查询）");
            int n = in.nextInt();
            if (n == 1) {
                Student stu = new Student();
                System.out.println("请输入学生姓名:");
                String sname = in.next();
                System.out.println("请输入学生性别:");
                String sex = in.next();
                System.out.println("请输入手机号:");
                String telephone = in.next();
                System.out.println("请输入qq号:");
                String qq = in.next();
                System.out.println("请输入微信号:");
                String wechat = in.next();
                System.out.println("请输入年级id:");
                int gradeid = in.nextInt();
                System.out.println("请输入加入班级时间:yyyy/mm/dd");
                String s = in.next();
                SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");//可以方便地修改日期格式
                System.out.println("请输入来自的城市:");
                String fromcity = in.next();
                System.out.println("请输入生日:yyyy/mm/dd");
                String s1 = in.next();
                try {
                    Date enterdate = dateFormat.parse(s);
                    Date birthday = dateFormat.parse(s1);
                    System.out.println("请输入密码:");
                    String pass = in.next();
                    stu.setPass(pass);
                    stu.setBirthday(birthday);
                    stu.setFromcity(fromcity);
                    stu.setEnterdate(enterdate);
                    stu.setGradeid(gradeid);
                    stu.setWechat(wechat);
                    stu.setQq(qq);
                    stu.setTelephone(telephone);
                    stu.setSex(sex);
                    stu.setSname(sname);
                    u.add(stu);
                } catch (ParseException e) {
                    e.printStackTrace();
                }

            } else if (n == 2) {
                Student stu = new Student();
                System.out.println("请输入要修改的学生学号:");
                int stuno = in.nextInt();
                System.out.println("请输入学生姓名:");
                String sname = in.next();
                System.out.println("请输入学生性别:");
                String sex = in.next();
                System.out.println("请输入手机号:");
                String telephone = in.next();
                System.out.println("请输入qq号:");
                String qq = in.next();
                System.out.println("请输入微信号:");
                String wechat = in.next();
                System.out.println("请输入年级id:");
                int gradeid = in.nextInt();
                System.out.println("请输入加入班级时间:yyyy/mm/dd");
                String s = in.next();
                SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");//可以方便地修改日期格式
                System.out.println("请输入来自的城市:");
                String fromcity = in.next();
                System.out.println("请输入生日:yyyy/mm/dd");
                String s1 = in.next();
                try {
                    Date enterdate = dateFormat.parse(s);
                    Date birthday = dateFormat.parse(s1);
                    System.out.println("请输入密码:");
                    String pass = in.next();
                    stu.setPass(pass);
                    stu.setBirthday(birthday);
                    stu.setFromcity(fromcity);
                    stu.setEnterdate(enterdate);
                    stu.setGradeid(gradeid);
                    stu.setWechat(wechat);
                    stu.setQq(qq);
                    stu.setTelephone(telephone);
                    stu.setSex(sex);
                    stu.setSname(sname);
                    stu.setStuno(stuno);
                    int a = u.update(stu);
                    if (a == 1) {
                        System.out.println("修改成功");
                    } else {
                        System.out.println("修改失败");
                    }
                } catch (ParseException e) {
                    e.printStackTrace();
                }
            } else if (n == 3) {
                System.out.println("请输入你要删除的序号：");
                int a = in.nextInt();
                if (u.del(a) == 1) {
                    System.out.println("删除成功！");
                }
            } else if (n == 4) {
//                List<Subject> list = u.query();
//                for (Subject s : list) {
//                    System.out.println(s);
//                }
                System.out.println("请输入你要查询的学号：");
                int a = in.nextInt();
                Student stu = u.query(a);
                System.out.println(stu);

            } else if (n == 5) {
//                List<Subject> list = u.query();
                System.out.println("请输入你要查询的名字：");
                String a = in.next();
                System.out.println("请输入你要查询的页：");
                int b = in.nextInt();
                System.out.println("请输入你要多少行：");
                int c = in.nextInt();
                List<Student> stu = u.query(a, b, c);
                for (Student s : stu) {
                    System.out.println(s);
                }
            } else if (n == 6) {
//                List<Subject> list = u.query();
                in.nextLine();
                System.out.println("请输入你要查询的姓名：");
                String a = in.nextLine();
                System.out.println("请输入你要查询的qq：");
                String qq = in.nextLine();
                System.out.println("请输入你要查询的telephone：");
                String telephone = in.nextLine();
                System.out.println("请输入你要查询的页：");
                int b = in.nextInt();
                System.out.println("请输入你要多少行：");
                int c = in.nextInt();
                List<Student> stu = u.query(a, qq, telephone, b, c);
                for (Student s : stu) {
                    System.out.println(s);
                }

            }
        }


    }
}
